package com.example;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Created by Risky57 on 2017/4/25.
 */

public class ClientDemo {

    public static void main (String[] args) throws IOException, InterruptedException {
        // 客户端
        Socket socket = new Socket("172.16.16.55", 80);
        OutputStream os = socket.getOutputStream();
        os.write("GET".getBytes());
        os.write(" ".getBytes());
        os.write("/code/auth.php".getBytes());
        os.write(" ".getBytes());
        os.write("HTTP/1.1".getBytes());
        os.write("\r\n".getBytes());
        os.write("Host: 172.16.16.55".getBytes());
        os.write("\r\n".getBytes());
        os.write("\r\n".getBytes());
        os.flush();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        StringBuilder builder = new StringBuilder();
        while ((line = br.readLine()) != null){
            builder.append(line + "\n");
        }

        System.out.println(builder);


//        for (int i = 0; i < 5; i++) {
//            os.write("客户端向服务端发送数据\n".getBytes());
//            os.flush();
//            Thread.sleep(1000);
//        }
//        os.write("bye\n".getBytes());
//        os.flush();
//        os.close();
//        is.close();
//        socket.close();
    }
}
